/*
 * Copyright (C) 2020 UNISOC Open Source Project
 *
 */

package com.android.systemui.screenshot;

import android.os.AsyncTask;
import com.android.internal.util.SwipeEvent;
import com.android.systemui.screenshot.GlobalScreenshotMoreAction;

/**
 * An AsyncTask that swipe screen in the background.
 */
public class SwipeTask extends AsyncTask<Void, Void, Void> {
    private final GlobalScreenshotMoreAction.SwipeInBackgroundData mParams;
    private final SwipeEvent mSwipeEvent;

    public SwipeTask(GlobalScreenshotMoreAction.SwipeInBackgroundData data) {
        mParams = data;
        mSwipeEvent = new SwipeEvent(mParams.context);
    }

    @Override
    protected Void doInBackground(Void... params) {
        int fromX = mParams.screenWidth / 2;
        //UNISOC: Modify for bug 1361055
        int fromY = mParams.screenHeight - (int)(mParams.screenHeight / 4 * mParams.scale) - SwipeEvent.SWIPE_OFFSET;
        int toX = fromX;
        int toY = mParams.screenHeight / 2 - SwipeEvent.SWIPE_OFFSET;
        int step = 20;
        mSwipeEvent.makeSwipeDown(fromX, fromY, toX, toY, step);
        return null;
    }

    @Override
    protected void onPostExecute(Void params) {
        mParams.swipeSentListener.onSwipeSent();
    }

    @Override
    protected void onCancelled(Void params) {
        mParams.swipeSentListener.onSwipeSent();
    }
}
